/*
 * @Description: 评论及评论回复表
 * @Author: Junhuang
 * @Date: 2022-02-21 22:44:51
 * @LastEditTime: 2022-02-22 15:00:13
 * @LastEditors: Junhuang
 * @Reference: 
 */
'use strict';

module.exports = {
  async up(queryInterface, Sequelize) {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    const { INTEGER, STRING, DATE, ENUM, TEXT } = Sequelize;
    // 创建表
    await queryInterface.createTable('comment', {
      id: {
        type: INTEGER(20), primaryKey: true, autoIncrement: true, comment: '主键id'
      },
      content: {
        type: TEXT, allowNull: false, defaultValue: '', comment: '评论内容'
      },
      // 发布此评论的用户id。如果此条是回复评论时，则此处为回复评论的用户id
      user_id: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '用户id',
        references: {
          model: 'user',
          key: 'id'
        },
        onDelete: 'cascade',
        onUpdate: 'restrict', // 更新时操作
      },
      video_id: {
        type: INTEGER,
        allowNull: false,
        defaultValue: 0,
        comment: '作品id',
        references: {
          model: 'video',
          key: 'id'
        },
        onDelete: 'cascade',
        onUpdate: 'restrict', // 更新时操作
      },
      reply_id: {
        type: INTEGER, allowNull: false, defaultValue: 0, comment: '回复id'
      },
      created_time: DATE,
      updated_time: DATE
    });
  },

  async down(queryInterface, Sequelize) {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
    return queryInterface.dropTable('comment');
  }
};
